package com.hyg.lib_music.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.utils.TextUtils;
import com.bumptech.glide.Glide;
import com.hyg.lib_common.WebView.WebViewActivity;
import com.hyg.lib_common.constant.UrlUtils;
import com.hyg.lib_music.R;
import com.hyg.lib_music.modle.KnowledgeArticData;
import com.hyg.lib_music.modle.knowledgeCategoryData;
import com.hyg.lib_music.ui.activity.KnowledgeArticDetailActivity;

import java.util.List;

/**
 * @author: Administrator
 * @date: 2021/4/12
 */
public class knowlegeCategoty23Adapter extends RecyclerView.Adapter<knowlegeCategoty23Adapter.ViewHolder> {

    Context context;
    List<KnowledgeArticData.DataDTO> list;

    public knowlegeCategoty23Adapter(Context context, List<KnowledgeArticData.DataDTO> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_knowledge_categoty_second, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.nameTv.setText(list.get(position).getDocTitle());
        Glide.with(context).load(list.get(position).getDocImg()).into(holder.imageView);
        holder.relativeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent starter = new Intent(context, WebViewActivity.class);
                starter.putExtra("url", UrlUtils.CATE_DOC+""+list.get(position).getId()+"&src=app&org=hyg");
                starter.putExtra("title",list.get(position).getDocTitle());
                context.startActivity(starter);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView nameTv;
        RelativeLayout relativeLayout;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.iv_image);
            nameTv = itemView.findViewById(R.id.tv_title);
            relativeLayout = itemView.findViewById(R.id.rl_root);
        }
    }

}